import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_swiper_plus/flutter_swiper_plus.dart';
import 'package:paly_android/bean/banner_entity.dart';
import 'package:paly_android/bloc/banner_bloc.dart';

class BannerPage extends StatefulWidget {
  BannerPage({Key? key}) : super(key: key);

  @override
  _BannerPageState createState() {
    return _BannerPageState();
  }
}

class _BannerPageState extends State<BannerPage> {
  late BannerBloc bloc;

  @override
  void initState() {
    LogUtil.e("banner initState");
    super.initState();
    bloc = BannerBloc();
    bloc.getBanner();
  }

  @override
  void didChangeDependencies() {
    LogUtil.e("banner didChangeD");

    super.didChangeDependencies();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
        create: (context) => bloc,
        child: BlocBuilder<BannerBloc, List<BannerEntity>>(
          builder: (BuildContext context, state) {
            LogUtil.d("BlocBuilder  builder");

            return Container(
                height: 200,
                child: Padding(
                  padding: EdgeInsets.only(bottom: 10),
                  child: Swiper(
                    itemBuilder: (BuildContext context, int index) {
                      return Image.network(state[index].imagePath!,
                          fit: BoxFit.fill);
                    },
                    itemCount: state.length,
                    pagination: SwiperPagination(),
                    // control: SwiperControl(),
                  ),
                ));
          },
        ));
  }
}
